<?php
namespace Pc\Controller;
use Think\Controller;
/*
 * pc端人员查询入口控制器 IndexController.class.php
 */
class PcController extends CommonController{
    //扩展配置文件
    private $kz_conf_file = "./Org/Data/kz_conf.json";
    //时间验证字段配置文件
    private $sj_conf_file = "./Org/Data/sj_zd_conf.json";


    /* 方法声明 */
    public function __construct(){
        parent::__construct();

    }

    /**
     * 员工自助入口方法
     *
     */
    public function index(){
        //获取员工唯一id标识 uuid
        $data = I('get.');
        $uuid = $data['id'];
        $token = $data['token'];
        if (!$uuid  || !$token ) {
            $this->error('员工参数缺失!');
            exit;
        }
        //dump($token);exit;
        //验证token
//        $arr = A('Aws')->check_token('/Pc/Pc/index',$token);
//        if(!$arr['type']){
//            $this->error($arr['msg']);
//            exit;
//        }

        session('uuid', $uuid);

        //拉取员工信息
        $this->getAwsUuidinfo($uuid);

        //获取首页导航数据
        $menu_list = $this->getMenuList();
        //获取第一个子集名
        $keys = array_keys($menu_list);
        $item = $keys[0];
        //dump($item);exit;

        /***************追加子集是否更改数据*****************/
        $this -> redis -> select(10);
        $userinfo = json_decode($this->redis->hget('user_list',$uuid),true)['information'];
        //dump($userinfo);exit;
        foreach($menu_list as $k=>&$v){
            $v['change_type'] = $userinfo[$v['name']]['change_type'];
        }

        //获取用户名
        $user_name = $userinfo['BO_CASC_HR_YGRS']['sublist']['YGXM']['value'];
        //dump($user_name);exit;

        $this->assign(array(
            'uuid'      => $uuid,
            'token'     => $token,
            'item'      => $item,
            'user_name' => $user_name,
            'menu'      => $menu_list,
            'corpid'    => $this->corpid,
        ));
        $this->display();
    }

    /**
     * 加载info模块,默认显示第一个子集
     */
    public function info(){
        $uuid = I('get.id');
        $menu = I('get.item');
        //1.获取常规字典数据
        $this->createDic();
        //2.获取已经提交审核的子集项
        $this -> redis -> select(11);
        if($change_item = $this->redis->hvals('items_'.$uuid)){
            $str = '';
            foreach($change_item as $k=>$v){
                $v = unserialize($v);
                $str .= implode(',',$v).',';
            }
            $change_item = rtrim($str,',');
        }else{
            $change_item = '';
        }

        //3.成员数据
        $userinfo = $this->getUserInfo($uuid);
        //dump($userinfo);exit;
        //4.获取子集数据
        $dat = $this->getSublist($userinfo,$menu);
        if(!$dat){
            $this -> error('未知menu数据!');
            exit;
        }

        //5.获取扩展配置文件
        $kz_info = json_decode(file_get_contents($this->kz_conf_file),true);
        $kz_info = $kz_info[$menu];
        //dump($kz_info);exit;

        //6.获取时间验证字段
        $sj_info = json_decode(file_get_contents($this->sj_conf_file),true);
        $sj_info = $sj_info[$menu];
        //dump($sj_info);exit;

        //7.获取type为file字段
        $file_zd = [];
        foreach($dat['sublist'] as $k=>$v){
            if($v['type'] =='FILE'){
                $file_zd[] = $k;
            }
        }
        $dat = $this->getFileInfo($uuid,$menu,$file_zd,$dat);
        //dump($dat);exit;
        $zp_key = array_keys($dat['sublist']['ZP']['value']);
        $zp_img = $dat['sublist']['ZP']['value'][$zp_key[0]]['href'];

        $this -> assign([
            'uuid'        => $uuid,
            'menu'        => $menu,
            'caption'     => $dat['caption'],
            'info'        => json_encode($dat),
            'kz_info'     => json_encode($kz_info),
            'dic'         => $this -> dic,
            'layer'       => $this -> layer,
            'change_item' => $change_item,
            'sj_info'     => json_encode($sj_info),
            'zp_img'      => $zp_img
        ]);
        $this -> display();
    }


}
